import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '../views/clms-system/Login'
import HomePage from '../views/clms-system/HomePage'
import ShowUser from '../views/clms-system/ShowUser'
import ShowRole from '../views/clms-system/ShowRole'
import ShowMenu from '../views/clms-system/ShowMenu'
import ShowLoginfo from '../views/clms-system/ShowLoginfo'
import UpdatePwd from '../views/clms-system/UpdatePwd'
import ShowInfo from '../views/clms-system/ShowInfo'
import ShowCar from '../views/clms-lease/ShowCar'
import ShowAllType from '../views/clms-lease/ShowAllType'
import ShowCarConfig from '../views/clms-lease/ShowCarConfig'
import ShowCarBrand from '../views/clms-lease/ShowCarBrand'
import ShowCarShop from '../views/clms-lease/ShowCarShop'
import ShowCarComment from '../views/clms-lease/ShowCarComment'
import Advertise from "../views/clms-market/Advertise";
import Customer from "../views/clms-market/Customer";
import CustomPlace from "../views/clms-market/CustomPlace";
import TbOrder from '../views/statistics/TbOrder'
import Echarts2 from '../views/statistics/Echarts2'
Vue.use(VueRouter);

const routes = [
    {
        path: '/',
        name: 'login',
        component: Login
    },
    {
        path: '/homePage',
        name: 'homePage',
        component: HomePage,
        children: [
            // 系统管理
            {
                path: '/showUser',
                name: 'ShowUser',
                component: ShowUser
            },
            {
                path: '/showRole',
                name: 'showRole',
                component: ShowRole
            },
            {
                path: '/showMenu',
                name: 'showMenu',
                component: ShowMenu
            },
            {
                path: '/showLoginfo',
                name: 'showLoginfo',
                component: ShowLoginfo
            },
            {
                path: '/updatePwd',
                name: 'updatePwd',
                component: UpdatePwd
            },
            {
                path: '/showInfo',
                name: 'showInfo',
                component: ShowInfo
            },
            // 租赁管理
            {
                path: '/showCar',
                name: 'showCar',
                component: ShowCar
            },
            {
                path: '/showAllType',
                name: 'showAllType',
                component: ShowAllType
            },
            {
                path: '/showCarConfig',
                name: 'showCarConfig',
                component: ShowCarConfig
            },
            {
                path: '/showCarBrand',
                name: 'showCarBrand',
                component: ShowCarBrand
            },
            {
                path: '/showCarShop',
                name: 'showCarShop',
                component: ShowCarShop
            },
            {
                path: '/showCarComment',
                name: 'showCarComment',
                component: ShowCarComment
            },

            {
                path: '/maintainShop',
                name: 'maintainShop',
                component: () => import( '../views/clms-CMMS/maintainShop.vue'),
            },
            // 客户管理
            {
                path: '/showClient',
                name: 'showClient',
                component: ()=>import('@/views/client/showClient.vue')
            },
            {
                path: '/showLevel',
                name: 'showLevel',
                component: ()=>import('@/views/client/showLevel.vue')
            },
            {
                path: '/showIntegration',
                name: 'showIntegration',
                component: ()=>import('@/views/client/ShowIntegration.vue')
            },
            {
                path: '/showCoupon',
                name: 'showCoupon',
                component: ()=>import('@/views/client/ShowCoupon.vue')
            },
            {
                path: '/showCouponRecord',
                name: 'showCouponRecord',
                component: ()=>import('@/views/client/ShowCouponRecord.vue')
            },
            {
                path: '/TbOrder',
                name: 'TbOrder',
                component: TbOrder
            },
            {
                path: '/Echarts2',
                name: 'Echarts2',
                component: Echarts2
            },
            // 营销管理
            {
                path: '/Advertise',
                name: 'Advertise',
                component: Advertise
            },
            {
                path: '/Customer',
                name: 'Customer',
                component: Customer
            },
            {
                path: '/CustomPlace',
                name: 'CustomPlace',
                component: CustomPlace
            },
            // 订单管理
            {
                path: '/showOrderInfo',
                name: 'showOrderInfo',
                component: ()=>import('@/views/clms-order/ShowOrderRecord.vue')
            },
        ]
    },
    {
        path: '/registeredMember',
        name: 'registeredMember',
        component: ()=>import('@/views/client/RegisteredMember.vue')

    }
];

const router = new VueRouter({
    routes
});
// 设置路由守卫
// to 表示要请的路由
// from 表示从那个路由过来的
// next 表示放行
router.beforeEach( (to,from,next) => {
    var path = to.path;
    if (path == '/') {
        return next();
    } else {
        var token = sessionStorage.getItem("token");
        if (token) {
            return next()
        } else {
            next('/')
        }
    }
});

export default router
